package com.easyctrl.ui.base;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnDismissListener; 
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;

import com.easyctrl.ldy.activity.R;

public class BaseDialog {

	private Window window;
	
	private Dialog baseDialog; 
	private BaseDialogOnDismissListener onDismissListener;
	public interface BaseDialogOnDismissListener {
		public void onDismiss(); 
	}  
	public void setOnDismissListener(BaseDialogOnDismissListener onDismissListener) {
		this.onDismissListener = onDismissListener;
	}
	
	public LayoutInflater mInflater; 
	public Context mContext;

	public BaseDialog(Context context){ 
		mInflater = LayoutInflater.from(context);
		this.mContext = context;
		
		baseDialog = new Dialog(context, R.style.BaseDialog);
		baseDialog.setCanceledOnTouchOutside(false); 
		baseDialog.setCancelable(true);
		
		window = baseDialog.getWindow();
		
		baseDialog.setOnDismissListener(new OnDismissListener() {
			
			@Override
			public void onDismiss(DialogInterface dialog) { 
				if(onDismissListener != null){
					onDismissListener.onDismiss();
				}
			}
		});
	}
	
	public void setContentView(int layoutResID){
		baseDialog.setContentView(layoutResID);
	}
	
	public void setContentView(View view){
		baseDialog.setContentView(view);
	}
	
	public View findViewById(int viewId){ 
		return baseDialog.findViewById(viewId);
	}
	
	public void show(){  
		baseDialog.show(); 
	} 
	
	public void dismiss(){
		baseDialog.dismiss();
	}
	
	public void cancel(){
		baseDialog.cancel();
	}

	public Window getWindow() {
		return window;
	} 
	
	public boolean isShowing(){
		return baseDialog.isShowing();
	}
}
